//
//  JSONModel.swift
//  SinaBlog
//
//  Created by 有何不可 on 16/1/5.
//  Copyright © 2016年 有何不可. All rights reserved.
//

import UIKit

class JSONModel: NSObject {

    /// created_at	string	微博创建时间
    var created_at: String?
    ///id	int64	微博ID
    var id: Int = 0
    ///text	string	微博信息内容
    var text: String?
    ///source	string	微博来源
    var source: String?
    //微博作者的用户信息字段
    var user: UserModel?
//    reposts_count	int	转发数
    var reposts_count: Int = 0
//    comments_count	int	评论数
    var comments_count: Int = 0
//    attitudes_count	int	表态数
    var attitudes_count: Int = 0
//   retweeted_status	object	被转发的原微博信息字段，当该微博为转发微博时返回
    var retweeted_status: JSONModel?
    //pic_urls缩略图地址数组
    var pic_urls: [PictureModel]?
    
    init(dict: [String: AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
        
        if let userInfo = dict["user"] as? [String: AnyObject]{
            
                user = UserModel(dict: userInfo)
        }
        
        // 跟user的一样,只不过是JSONModel自身的属性
        if let retweetedDict = dict["retweeted_status"] as? [String: AnyObject] {
            
            retweeted_status = JSONModel(dict: retweetedDict)
        }
        
        if let picDicts = dict["pic_urls"] as? [[String: AnyObject]] {
            
            pic_urls = [PictureModel]()
            
            for picDict in picDicts {
                
                let pic = PictureModel(dict: picDict)
                
                pic_urls?.append(pic)
            }
        }
//        print(source)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
   
  
}
